package main

import (
	"fmt"
	"io/ioutil"
)

func ifDemo() {
	const filename = "abc.txt"
	//contents, err := ioutil.ReadFile(filename)
	//if err != nil {
	//	fmt.Println(err)
	//} else {
	//	fmt.Printf("%s\n", contents)
	//}
	//如上可以改写成：
	if contents, err := ioutil.ReadFile(filename); err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
}

func grade(score int) string {
	g := ""
	switch {
	case score < 0 || score > 100:
		panic(fmt.Sprintf("Wrong score: %d", score)) //panic:会中断执行并报错
	case score < 60:
		g = "F"
	case score < 70:
		g = "C"
	case score < 80:
		g = "B"
	case score < 90:
		g = "A"
	case score < 95:
		g = "S"
	case score <= 100:
		g = "S+"
	}
	return g

}

func main() {
	//ifDemo()
	//fmt.Println(
	//	grade(0), grade(55), grade(65), grade(79), grade(87), grade(91), grade(95), grade(98),
	//)
	fmt.Println(
		grade(0), grade(55), grade(65), grade(79), grade(87), grade(91), grade(95), grade(98), grade(102), grade(-3))
}
